//
//  CYABPhoneCell.m
//  CreditAddressBook
//
//  Created by Lee on 15/10/8.
//  Copyright © 2015年 Lee. All rights reserved.
//

#import "CYABPhoneCell.h"
#import "CYPerson.h"
#import "CYDialTool.h"
#import "CYCallCenter.h"

@interface CYABPhoneCell ()

@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;

@end

@implementation CYABPhoneCell

- (void)setPhone:(NSString *)phone {
    _phone = phone;
    
    self.phoneLabel.text = phone;
}

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *ID = @"CYABPhoneCell";
    CYABPhoneCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"CYABPhoneCell" owner:nil options:nil] lastObject];
    }
    return cell;
}

- (void)awakeFromNib {
    
}

- (IBAction)callBtn:(id)sender {
    [[CYCallCenter sharedCallCenter] callWithNumber:self.phone name:self.person.name person:self.person success:^{
        CYLog(@"通话成功");
        
        //发送通知更新通讯记录
        [CYNotificationCenter postNotificationName:CYCallStateDisconnectedKey object:nil];
    } failure:^{
        CYLog(@"通话失败");
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
